package com.dingzhen.listener;

import lombok.SneakyThrows;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;

import javax.imageio.IIOException;
import javax.websocket.Session;
import java.io.IOException;


public class RedisReceiverListener implements MessageListener {

    private Session session;


    /**
     * 处理接收到的对象的回调
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        String msg =new String(message.getBody());
        System.err.println(new String(pattern) +" 主题发布： "+msg);
        if(null!=session && session.isOpen()){
           try {
               session.getBasicRemote().sendText(msg);
           }catch (IOException e){
               e.printStackTrace();
               System.err.println("处理接收到的对象的回调报错了！！！！");
           }
        }
    }














    public Session getSession() {
        return session;
    }

    public void setSession(Session session) {
        this.session = session;
    }
}
